<include file="public@storage"/>
<head>
    <style>
        p {
            margin-top: 30px;
            margin-bottom: 30px;
            font-family: '黑体';
            font-size: 24px
        }
    </style>
</head>
<body>
<div>
    <div align="center" style="width: 100%;margin-top:5%">
        <div align="center" style="width: 100% ;">
            <div class="panel panel-primary">
                <div class="panel-heading" >
                    <h3 align="left" class="panel-title">入库单</h3>
                </div>
                <div class="panel-body"  style="padding-top:5%;padding-bottom:5%;">
                    <div class="d1" style="height:55px;">
                        <div class="mybutton" style="height: 55px;">
                            <input type="text" style="width: 20%;" name="purchase_id" id="purchase_id" class="mui-btn mui-btn--raised"  placeholder="请输入入库单号"/>
                            <button type="button" class="mui-btn mui-btn--raised mui-btn--primary" id="ask">K3导入</button>
                            <button type="button" class="mui-btn mui-btn--raised mui-btn--primary" onclick=location="{:url('storage/Purchase/excel')}">Excel导入</button>
                            <!--<button type="button" class="mui-btn mui-btn&#45;&#45;raised mui-btn&#45;&#45;primary" onclick=location="{:url('storage/Purchase/manual')}">手动输入</button>-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="loading" style="background-color:#000000;opacity:0.5;z-index: 100;height: 100%;width: 100%;top: 0;position: absolute;display: none">
        <div style="position:absolute;left: 50%;top: 50%;z-index:101;margin-left: -164px;margin-top: -100px;">
            <img src="__STATIC__/images/animate.gif">
        </div>
    </div>
</div>
    <script>
        $(function () {
            $("#ask").click(function(){
                var purchase_id = $("#purchase_id").val();
                if(purchase_id === '' || purchase_id.length === 0){
                    layer.msg('请输入订单号');
                    return ;
                }
                $.ajax({
                    url: "{:url('storage/Purchase/addPurchaseFromK3')}",
                    dataType:"json",
                    type:'POST',
                    data:{purchaseId:purchase_id},
                    beforeSend:function () {
                        $('.loading').show();
                    }, complete:function(){
                        $('.loading').hide();
                    },success:function(res){
                        if(res.success===true){
                            layer.msg(res.message);
                            //将开头写到前面
                            var str = /\w[A-z]+/.exec(purchase_id)[0];
                            $('#purchase_id').val(str);
                        }else if(res.success === false){
                            layer.msg(res.message);
                        }
                    },error:function(){
                        layer.msg('网络错误');
                    }
                })
            });
        });

    </script>
</body>
</html>

